package cn.kgc.service.impl;

import cn.kgc.dto.MalfunctionDto;
import cn.kgc.dto.MalfunctionOptionsDto;
import cn.kgc.mapper.MalfunctionMapper;
import cn.kgc.mapper.MalfunctionOptionsMapper;
import cn.kgc.pojo.Malfunction;
import cn.kgc.service.MalfunctionService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 故障 服务实现类
 * </p>
 *
 * @author qf
 * @since 2022-03-03
 */
@Service
public class MalfunctionServiceImpl extends ServiceImpl<MalfunctionMapper, Malfunction> implements MalfunctionService {
    private final MalfunctionMapper malfunctionMapper;
    private final MalfunctionOptionsMapper malfunctionOptionsMapper;

    public MalfunctionServiceImpl(MalfunctionMapper malfunctionMapper, MalfunctionOptionsMapper malfunctionOptionsMapper) {
        this.malfunctionMapper = malfunctionMapper;
        this.malfunctionOptionsMapper = malfunctionOptionsMapper;
    }

    public List<MalfunctionDto> specList(Long modelId){
        List<MalfunctionDto> list=null;

        list = malfunctionMapper.getMalById(modelId);
        if(list!=null){
            for (MalfunctionDto malfunctionDto : list) {
                Long id = malfunctionDto.getId();
                List<MalfunctionOptionsDto> dtoList = malfunctionOptionsMapper.getMalOpenById(id);
                malfunctionDto.setOptionsList(dtoList);
            }
        }
        return list;
    }



}
